﻿using AutoMapper;
using IOA.MES.DataAccess.Entity;
using IOA.MES.DataAccess.VModel;
using System.Linq;

namespace IOA.MES.DataAccess
{
    public class MapperConvert
    {
        public void InitMapper(IMapperConfigurationExpression cfg)
        {
            var assembly = System.Reflection.Assembly.GetExecutingAssembly();
            var types = assembly.GetTypes().ToList();
            foreach (var entityType in types)
            {
                if (string.Equals(entityType.Namespace, $"{assembly.GetName().Name}.Entity", System.StringComparison.CurrentCultureIgnoreCase))
                {
                    var modelType = types.FirstOrDefault(_ => string.Equals(_.FullName, $"{assembly.GetName().Name}.VModel.V{entityType.Name}", System.StringComparison.CurrentCultureIgnoreCase));
                    if (modelType != null)
                    {
                        if (modelType.GetProperty("CNCreateBy") != null)
                        {
                            cfg.CreateMap(entityType, modelType).ForMember("CNCreateBy", opt =>
                            {
                                opt.Ignore();
                            });
                        }
                        if (modelType.GetProperty("CreateTimeStr") != null)
                        {
                            cfg.CreateMap(entityType, modelType).ForMember("CreateTimeStr", opt =>
                            {
                                opt.Ignore();
                            });
                        }
                        if (modelType.GetProperty("CNModifyBy") != null)
                        {
                            cfg.CreateMap(entityType, modelType).ForMember("CNModifyBy", opt =>
                            {
                                opt.Ignore();
                            });
                        }
                        if (modelType.GetProperty("ModifyTimeStr") != null)
                        {
                            cfg.CreateMap(entityType, modelType).ForMember("ModifyTimeStr", opt =>
                            {
                                opt.Ignore();
                            });
                        }
                    }
                }
            }

            cfg.CreateMap<User, VUser>().ForMember(d => d.Roles, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Workshops, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Token, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Module, VModule>().ForMember(d => d.SubModules, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.DisplayTitle, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Role, VRole>().ForMember(d => d.DepartmentName, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Workshop, VWorkshop>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.DutyNames, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.LineNames, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Lines, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<WorkshopDuty, VWorkshopDuty>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.WorkTime, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Department, VDepartment>().ForMember(d => d.Roles, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<AssemblyLine, VAssemblyLine>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Machine, VMachine>().ForMember(d => d.CNMachineType, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Order, VOrder>().ForMember(d => d.OrderTimeStr, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<WorkOrder, VWorkOrder>().ForMember(d => d.CustomerId, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CustomerCode, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CustomerName, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.QLevels, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.OutputPowers, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.BinningPowers, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.StartDateStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.EndDateStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.WorkOrderTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.ReviewTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Boms, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<StandardPiece, VStandardPiece>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Warehouse, VWarehouse>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNWarehouseType, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<WarehouseArea, VWarehouseArea>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<WarehouseLocation, VWarehouseLocation>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Pack, VPack>().ForMember(d => d.CNPackStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNStockStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNPackInspectStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Products, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.PackCondition, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Outbounded, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Loaded, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<InboundInspect, VInboundInspect>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Products, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<InboundInspectProduct, VInboundInspectProduct>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<ViaSiteConfig, VViaSiteConfig>().ForMember(d => d.CustomerCode, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CustomerName, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.ConfigModel, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Inbound, VInbound>().ForMember(d => d.Products, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Packs, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Outbound, VOutbound>().ForMember(d => d.CNOutboundBy, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Products, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Packs, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.OutboundTimeStr, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Cabinet, VCabinet>().ForMember(d => d.CNPackStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Packs, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<BinningSchema, VBinningSchema>().ForMember(d => d.BinningPowers, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<BinningPower, VBinningPower>().ForMember(d => d.Currents, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<LoadInspect, VLoadInspect>().ForMember(d => d.CNLoadBy, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.FinishTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Packs, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Component, VComponent>().ForMember(d => d.CNProduceStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNProductStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNStockStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.DistributeTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.WeldingTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.LaminatedTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.EL1TimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.TopTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.NQCTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.FramingTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CleanTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.IVTestTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.InsulatedResistanceTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.EL2TimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.NameplatePrintingTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.FinalInspectionTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.PackTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.InboundTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.OutboundTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.LoadTimeStr, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<Downgrade, VDowngrade>().ForMember(d => d.CNReviewedBy, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.ReviewTimeStr, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<LockRecord, VLockRecord>().ForMember(d => d.CNLockedBy, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNUnLockedBy, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.LockedTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.UnLockedTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNCurSite, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNLockSite, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<ObaInspect, VObaInspect>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Packs, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Sites, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<ObaInspect, VObaInspectInfo>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Packs, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Sites, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CustomerCode, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CustomerName, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<ObaSite, VObaSite>().ForMember(d => d.CNSiteType, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<ReworkOrder, VReworkOrder>().ForMember(d => d.Items, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Sites, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Boms, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNProduceStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNReviewStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNReviewBy, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.ReviewTimeStr, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<ProductViaSiteRecord, VProductViaSiteRecord>().ForMember(d => d.CNSiteType, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<ProductCategory, VProductCategory>().ForMember(d => d.Children, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<DispatchOrder, VDispatchOrder>().ForMember(d => d.Products, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<CarryOverOrder, VCarryOverOrder>().ForMember(d => d.Products, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<AllocateOrder, VAllocateOrder>().ForMember(d => d.AllocateTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.BatchLastAsyncTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Products, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<DeliveryOrder, VDeliveryOrder>().ForMember(d => d.DeliveryDateStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.Cabinets, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<BadReason, VBadReason>().ForMember(d => d.BadTypeName, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<SortRule, VSortRule>().ForMember(d => d.CurSortNo, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.OrderNos, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.WorkOrderNos, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.NameplateModels, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.PowerLevels, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CurrentLevels, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.QLevels, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.ComponentColors, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.JunBoxSpecses, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.JunBoxFactories, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.BackPlanSpecses, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.BackPlanFactories, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.AluFrameSpecses, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.AluFrameFactories, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.BatterySpecses, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.BatteryFactories, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.BadReasons, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<FootProtectConfig, VFootProtectConfig>().ForMember(d => d.FootProtectSortNoList, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.OverTurnSortNoList, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<SortStack, VSortStack>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<SortRecord, VSortRecord>().ForMember(d => d.CNStatus, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<WmsInboundTask, VWmsInboundTask>().ForMember(d => d.CnStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.LastTryTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.PackTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CabinetTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CnReceiveStatus, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.ReceiveTimeStr, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<CompenCellRecord, VCompenCellRecord>().ForMember(d => d.CnCompenReason, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CnCompenReason, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.StartTimeStr, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.EndTimeStr, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<LineMaterialBill, VLineMaterialBill>().ForMember(d => d.Items, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CnBillType, opt =>
            {
                opt.Ignore();
            });
            cfg.CreateMap<ProductViaSiteTopData, VProductViaSiteTopData>().ForMember(d => d.MachineName, opt =>
            {
                opt.Ignore();
            }).ForMember(d => d.CnWorkingStatus, opt =>
            {
                opt.Ignore();
            });
        }
    }
}
